
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试存储</title>
    <script >
        var sz=[];
        sz[0]={"id":1,"ans":"a"};
        sz[1]={"id":2,"ans":"cd"};
        sz[2]={"id":3,"ans":"abc"};
        function save() {
            //js object-->string
            var s=JSON.stringify(sz);
            localStorage.setItem("daan",s);
        }
        function getinfo() {
            var s=localStorage.getItem("daan");
            //string
            var sz=JSON.parse(s);
            console.log(sz[1].ans);
        }
    </script>
</head>
<body>
<button onclick="save()" value="存储">存储</button>
<button onclick="getinfo()" value="取出">取出</button>
</body>
</html>
